<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学号">
              <a-input placeholder="请输入..." v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="姓名">
              <a-input placeholder="请输入..." v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="论文录入状态">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.lwlrzt">
                <a-select-option v-for="i in TYPE0501" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <!-- <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="论文上传状态">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.lwwjsczt" >
                <a-select-option v-for="i in TYPE0502" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col> -->
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch :disabled="selectYxConfig.length === 1" optionFilterProp="children" v-model="queryParam.yx" @change="handleSelectYx">
                <a-select-option v-for="i in selectYxConfig" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="专业">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zy">
                    <a-select-option v-for="i in selectZyConfig" :key="i.zyh" :value="i.zyh">{{ i.zyh+'-'+i.zymc }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="年级">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.nj">
                    <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item label="学生类别">
                  <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.xslb">
                    <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
                <a-form-item
                  label="学生来源"
                >
                  <a-select :allowClear="true" v-model="queryParam.xslxm">
                    <a-select-option v-for="i in TYPE0503" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
          </template>
          <a-col :sm="{span:24}" :xl="{span:advanced?24:12}" style="text-align:center">
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button type="primary" @click="handleExport">导出</a-button>
              <a-button @click="queryParam = {};$refs.table.refresh()">重置</a-button>

            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <STable 
      v-if="initDone"
      ref="table" 
      size="default" 
      rowKey="id" 
      :columns="columns" 
      :data="loadData" 
      :scroll="{ x: 1500 }">
        <a slot="lwjbxx" slot-scope="text, record, index" v-if="record.lwwjlj" @click="getLwxx(record)">{{text}}</a>
        <span slot="lwjbxx" slot-scope="text, record, index" v-else>{{text}}</span>

        <a slot="lwwjlj" slot-scope="text, record, index" v-if="text" @click="handleDownPaper(record.id)">下载</a>
      </STable>
    </a-card>
    <submit-info :visible="visible" @close="handleEditClose" :itemList="itemList"></submit-info>
</div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import SubmitInfo  from './submitInfo.vue'

const selectArr = [
  'TYPE0501', //论文录入状态
  'TYPE0502', //论文上传状态
  'TYPE0126', //年级
  'TYPE0075' //学生类别
]

export default {
  components: {
    STable,SubmitInfo
  },
  data () {
    return {
      itemList: '',
      visible: false,
      advanced: true,
      // 条件配置
      selectYxConfig: [], //院系
      selectZyConfig: [], //专业
      // 查询参数
      queryParam: {
        yx: '',
        zy: '',
        lwlrzt:'',
        lwwjsczt:'',
        xm: '',
        xh: '',
        xslb: '',
        nj: ''
      },
      // 表头
      columns: [
        {
          title: '学号',
          dataIndex: 'xh',
          scopedSlots: { customRender: 'lwjbxx' }
        },
        {
          title: '姓名',
          dataIndex: 'xm'
        },
        {
          title: '论文',
          dataIndex: 'lwwjlj',
          scopedSlots: { customRender: 'lwwjlj' }
        },
        {
          title: '院系',
          dataIndex: 'yxmc'
        },
        {
          title: '专业',
          dataIndex: 'zymc'
        },
        {
          title: '导师',
          dataIndex: 'dsxm'
        },
        {
          title: '年级',
          dataIndex: 'ssnjmc'
        },
        {
          title: '学生类别',
          dataIndex: 'xslbmc'
        },
        {
          title: '论文录入状态',
          dataIndex: 'lwlrztmc'
        },
        // {
        //   title: '论文上传状态',
        //   dataIndex: 'lwwjscztmc'
        // },
        // {
        //   title: '自评表上传状态',//未找到字段
        //   dataIndex: 'tjzymc'
        // },
        // {
        //   title: '复评选项',//未找到字段
        //   dataIndex: 'tjyjfxmc'
        // }
      ],
       // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign(this.queryParam, parameter)
        return this.$api.degree.paperList(params).then(res => {
          console.log(res)
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      initDone: false
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0075: state => state.app['TYPE0075'], // 学生类别
      TYPE0126: state => state.app['TYPE0126'], // 年级
      TYPE0501: state => state.app['TYPE0501'], // 论文录入状态
      TYPE0502: state => state.app['TYPE0502'], // 论文上传状态
      TYPE0503: state => state.app['TYPE0503'],
    })
  },
  created () {
    this.initSelectMenu()
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectYxConfig = res[0].data
        if (res[0].data.length === 1) {
          this.$set(this.queryParam, 'yx', res[0].data[0].dwh)
          this.handleSelectYx(res[0].data[0].dwh)
        }
        this.initDone = true
      })
    },
    //选择院系
    handleSelectYx(code){
      this.selectZyConfig = [];
      this.$set(this.queryParam,"zy","");
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.selectZyConfig = res.data;
      })
    },
    // 导出
    handleExport () {
      this.$export('/degree/xwlwxx/exp', this.queryParam)
    },
    //下载
    handleDownPaper(id){
      this.$export(`/degree/xwlwxx/downloadLw?id=${id}`)
    },
    //查看论文信息
    getLwxx(item){
      this.visible = true
      this.itemList = item
    },
    //关闭编辑窗口
    handleEditClose(){
      this.visible = false;
    },
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
